const unitConvert = function (num) {
  if (num) {
    var moneyUnits = ['', '万']
    var dividend = 10000
    var curentNum = num // 转换数字
    var curentUnit = moneyUnits[0] // 转换单位
    for (var i = 0; i < 2; i++) {
      curentUnit = moneyUnits[i]
      if (strNumSize(curentNum) < 5) {
        return num
      }
    }
    curentNum = curentNum / dividend
    var m = {
      num: 0,
      unit: ''
    }
    m.num = curentNum.toFixed(2)
    m.unit = curentUnit
    return m.num + m.unit
  }
}
function strNumSize (tempNum) {
  var stringNum = tempNum.toString()
  var index = stringNum.indexOf('.')
  var newNum = stringNum
  if (index !== -1) {
    newNum = stringNum.substring(0, index)
  }
  return newNum.length
}

const getNowFormatDate = function () {
  var date = new Date()
  var seperator1 = '-'
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var strDate = date.getDate()
  if (month >= 1 && month <= 9) {
    month = '0' + month
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = '0' + strDate
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate
  return currentdate
}

const funDate = function (aa) {
  var date1 = new Date()
  if (!aa) {
    var time1 = date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' + date1.getDate()// time1表示当前时间
    return time1
  } else {
    var date2 = new Date(date1)
    date2.setDate(date1.getDate() + aa)
    var time2 = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate()
    return time2
  }
}

export default{
  unitConvert,
  getNowFormatDate,
  funDate
}
